<?php

/*
* This scripts provides the data for autocomplete when typing usernames.
*
* @method REQUEST	
* @header term Supposedly starting letters of a username
*
* @return json encoded data in a jquery select form
*         Data in the select form is a username starting with the entered letters 
*/

if ( !isset($_REQUEST['term']) )
    exit;
	
require_once("../functions/connect_to_database.php");

$rs = mysql_query('select username from members where username like "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by username asc limit 0,100');

$data = array();
if ( $rs && mysql_num_rows($rs) )
{
    while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
    {
        $data[] = array(
            'label' => $row['username'],
            'value' => $row['username']
        );
    }
}

echo json_encode($data);
flush();
?>
